CFLAGS = -ansi -Wall -pedantic -Werror
CC = gcc
TESTFLAG = -DTEST_DLINK_LIST

PUBLIC  =  public
SOURCE  =  source

DEBUG   = bin/Debug
RELEASE = bin/Release
TEST_D  = $(DEBUG)/test
TEST_R  = $(RELEASE)/test

BINDIRS	= $(DEBUG) $(RELEASE)
FILES   = DLinkList
NOTE	= dlink [exec file with testes] libs[libraries] all [make libraries and exec]
OUTNAME = list

print:
		@echo $(NOTE)

dlink:

		@echo dlink executables with $(TESTFLAG) at  $(DEBUG) $(RELEASE)
		@$(CC) $(TESTFLAG)              $(CFLAGS) $(SOURCE)/$(FILES).c  $(SOURCE)/test.c -I $(PUBLIC) -o $(RELEASE)/$(OUTNAME)
		@$(CC) $(TESTFLAG) -D_DEBUG -g  $(CFLAGS) $(SOURCE)/$(FILES).c  $(SOURCE)/test.c -I $(PUBLIC) -o $(DEBUG)/$(OUTNAME)

all:	remove create_libs dlink
		@echo made_dlink clean
		@echo -----

install:
		@echo install
		@mkdir -p $(DEBUG)
		@mkdir -p $(RELEASE)

create_libs: 	install DLinkList.o
		@echo created static and dynamic libs
		@for i in $(DEBUG) $(RELEASE); do ar -crs $$i/libDLinkList.a  $$i/DLinkList.o ; done;
		@for i in $(DEBUG) $(RELEASE); do gcc -shared -o $$i/libDLinkList.so  $$i/DLinkList.o ; done;

DLinkList.o:	$(PUBLIC)/DLinkList.h $(SOURCE)/DLinkList.c
		@echo DLinkList.o
		@$(CC) -c    $(CFLAGS) $(SOURCE)/$(FILES).c           -I $(PUBLIC) -o $(RELEASE)/$(FILES).o
		@$(CC) -c -g $(CFLAGS) -D_DEBUG $(SOURCE)/$(FILES).c  -I $(PUBLIC) -o $(DEBUG)/$(FILES).o

clean:
		@echo bin is clean
		@for i in $(BINDIRS); do /bin/rm $$i/*.o; done;
		/bin/rm -r -f obj/

remove:
		@echo bin removed
		@/bin/rm -r -f ./bin 2> /dev/null
		@/bin/rm -R -f */*~ *~
